package com.xl98.controller;


import com.xl98.entity.*;
import com.xl98.service.AppointmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ls
 * @since 2020-05-15
 */
@RestController
@Api(value = "预约",tags = {"预约"})
@RequestMapping("/appointment")
public class AppointmentController {
    @Autowired
    private AppointmentService appointmentService;

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/all", method = RequestMethod.POST)
    @ApiOperation(value = "查询所有预约")
    public Result findAll() {
        List<Appointment> list = appointmentService.selectAll();
        return ResultFactory.buidResult(ResponseCode.SUCCESS_CODE,ResponseCode.SUCCESS_FIND,list);
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "添加预约")
    public Result insert(@RequestBody Appointment appointment){
        return ResultFactory.buildSuccessResult(appointmentService.insert(appointment));
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改预约")
    public Result update(@RequestBody Appointment appointment){
        return ResultFactory.buildSuccessResult(appointmentService.update(appointment));
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除预约")
    public Result delete(String id){
        return ResultFactory.buildSuccessResult(appointmentService.delete(id));
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/selectById", method = RequestMethod.POST)
    @ApiOperation(value = "根据id查询预约")
    public Result selectById(String id) {
        Appointment appointment = appointmentService.selectById(id);
        return ResultFactory.buidResult(ResponseCode.SUCCESS_CODE,ResponseCode.SUCCESS_FIND,appointment);
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/selectByUserId", method = RequestMethod.POST)
    @ApiOperation(value = "根据用户id查询预约")
    public Result selectByUserId(String userId) {
        List<Appointment> list = appointmentService.selectByUserId(userId);
        return ResultFactory.buidResult(ResponseCode.SUCCESS_CODE,ResponseCode.SUCCESS_FIND,list);
    }

    @CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
    @ResponseBody
    @RequestMapping(value = "/selectByConsultantId", method = RequestMethod.POST)
    @ApiOperation(value = "根据咨询师id查询预约")
    public Result selectByConsultantId(String consultantId) {
        List<Appointment> list = appointmentService.selectByConsultantId(consultantId);
        return ResultFactory.buidResult(ResponseCode.SUCCESS_CODE,ResponseCode.SUCCESS_FIND,list);
    }
}

